/**
 * 
 */
package com.googlecode.pcapj;

import java.net.InetAddress;
import java.util.Arrays;

import org.bridj.BridJ;
import org.bridj.Pointer;

import com.googlecode.pcapj.bridj.sockaddr;

/**
 * 
 */
class SocketAddressImpl implements SocketAddress{
	private int socketFamily;
	private byte[] socketAddress; 
	private InetAddress inetAddress;
	
	/**
	 * 
	 */
	public SocketAddressImpl(Pointer<sockaddr> sockaddr) {
		super();
		sockaddr sa = sockaddr.get();
		socketFamily = sa.sa_family() & 0xffff;
		socketAddress = sockaddr.getBytes((int)BridJ.sizeOf(sockaddr.class));
	}

	/* (non-Javadoc)
	 * @see com.googlecode.pcapj.SocketAddress#getSocketFamily()
	 */
	public int getSocketFamily() {
		return socketFamily;
	}

	/* (non-Javadoc)
	 * @see com.googlecode.pcapj.SocketAddress#getSocketAddress()
	 */
	public byte[] getSocketAddress() {
		return socketAddress;
	}

	/* (non-Javadoc)
	 * @see com.googlecode.pcapj.SocketAddress#getInetAddress()
	 */
	public InetAddress getInetAddress() {
		return inetAddress;
	}
	/**
	 * @param inetAddress the inetAddress to set
	 */
	void setInetAddress(InetAddress inetAddress) {
		this.inetAddress = inetAddress;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return getClass().getSimpleName() + "[socketFamily=" + socketFamily
				+ ", socketAddress=" + Arrays.toString(socketAddress)
				+ ", inetAddress=" + inetAddress + "]";
	}
}
